import { request } from "../../request/index.js";
import regeneratorRuntime from '../../lib/runtime/runtime';
// pages/search/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goods:[],
    isFocus:false,
    inpvalue:""
  },
  TimeId:-1,
  // 输入框的值改变
  handleInput(e){
    const {value}= e.detail;
    if(!value.trim()){
    this.setData({
      goods:[],
      isFocus:false
    })
      return;
    }
    this.setData({
      isFocus:true
    })
    clearTimeout(this.TimeId);
    this.TimeId=setTimeout(()=>{
      this.qsearch(value);
    },100);

  },
  async qsearch(query){
    const res=await request({url:"/goods/qsearch",data:{query}});
    // console.log(res);
    this.setData({
      goods:res.data.message
    })
  },
  // 点击取消按钮
  handleCancel(){
    this.setData({
      goods:[],
      isFocus:false,
      inpvalue:""
    })
  }
})